package com.my.zxsyd.controller.admin;


import com.my.zxsyd.entity.Yonghu;
import com.my.zxsyd.qpage.QPage;
import com.my.zxsyd.service.IYonghuService;
import com.my.zxsyd.util.ResultView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lbk
 * @since 2024-02-19
 */
@RestController
@RequestMapping("/api/admin/yonghu")
public class YonghuController {

    @Autowired
    private IYonghuService service;

    /**
     * 列表分页
     * @param obj
     * @return
     */
    @GetMapping("/getPageList")
    public ResultView getPageList(QPage qPage, Yonghu obj) {
        return this.service.getPageList(qPage,obj);
    }

    /**
     * 下拉不分页用户列表
     * @return
     */
    @GetMapping("/getSelectList")
    public ResultView getSelectList() {
        List<Yonghu> obj=this.service.list();
        return ResultView.ok(obj);
    }

    /**
     * 根据ID获取当前数据
     * @return
     */
    @GetMapping("/getById")
    public ResultView getById(@NotNull(message = "ID不能为空") Integer id) {
        Yonghu obj=this.service.getById(id);
        return ResultView.ok(obj);
    }

    /**
     * 新增
     * @param obj
     * @return
     */
    @PostMapping("/add")
    public ResultView add(Yonghu obj) {
        return this.service.add(obj);
    }

    /**
     * 删除
     * @return
     */
    @PostMapping("/del")
    public ResultView del(@NotNull(message = "ID不能为空") Integer id) {
        return this.service.del(id);
    }


    /**
     * 修改
     * @param obj
     * @return
     */
    @PostMapping("/up")
    public ResultView update(Yonghu obj) {
        return this.service.up(obj);
    }



}
